package cn.smdq.ch.auth.center.service;

import cn.smdq.ch.common.vo.UserVO;
import cn.smqd.ch.upms.client.UpmsClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @Description TODO
 * @Author shuimodanqing
 * @Date 2019/1/21  1:04 PM
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private UpmsClient upmsClient;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserVO userVO = upmsClient.findUserByUsername(username);
        if (userVO == null) {
            throw new UsernameNotFoundException("用户名不存在或者密码错误: " + username);
        }
        return new UserDetailImpl(userVO);
    }
}
